<template>
	<view :data-theme="theme">
		<!-- <form @submit="formSubmit" report-submit='true'> -->
			<view class='personal-data borderPad'>
				<view class='list borRadius14'>
					<view class='item acea-row row-between-wrapper'>
						<view>发票单据号</view>
						<view class='input fontColor'>
							<view class="weui-input">{{invoice.closingNo}}</view>
						</view>
					</view>
					<view class='item acea-row row-between-wrapper'>
						<view>纳税人名称</view>
						<view class='input'>
							<view>{{invoice.cardholder}}</view>
						</view>
					</view>
					<view class='item acea-row row-between-wrapper'>
						<view>纳税人身份证号</view>
						<view class='input'>
							<view>{{invoice.idCard}}</view>
						</view>
					</view>
					<view class='item acea-row row-between-wrapper'>
						<view>纳税人手机号</view>
						<view class='input'>
							<view>{{invoice.mobile}}</view>
						</view>
					</view>
					<view class='item acea-row row-between-wrapper'>
						<view>开户银行</view>
						<view class='input'>
							<view>{{invoice.bankName}}</view>
						</view>
					</view>
					<view class='item acea-row row-between-wrapper'>
						<view>银行账户</view>
						<view class='input'>
							<view>{{invoice.bankCardNo}}</view>
						</view>
					</view>
					<view class='item acea-row row-between-wrapper'>
						<view>开户行地址</view>
						<view class='input'>
							<view>{{invoice.bankAddress}}</view>
						</view>
					</view>
					<view class='item acea-row row-between-wrapper'>
						<view>开票金额</view>
						<view class='input'>
							<view>￥{{invoice.closingPrice}}</view>
						</view>
					</view>
					<view class='item acea-row row-between-wrapper'>
						<view>开票税率</view>
						<view class='input'>
							<view>1%</view>
						</view>
					</view>

					<view class='item acea-row row-between-wrapper'>
						<view>开票状态</view>
						<view class='input'>
							<view v-if="invoice.invoiceStatus=='0'">未开票</view>
							<view v-if="invoice.invoiceStatus=='1'">开票中</view>
							<view v-if="invoice.invoiceStatus=='2'">已开票</view>
						</view>
					</view>
					<view class='item acea-row row-between-wrapper'>
						<view>结算状态</view>
						<view class='input'>
							<view v-if="invoice.auditStatus=='0'">待审核</view>
							<view v-if="invoice.auditStatus=='1'">审核通过</view>
							<view v-if="invoice.auditStatus=='2'">审核失败</view>
						</view>
					</view>

					<view class='item acea-row row-between-wrapper' v-if="invoice.auditStatus=='2'">
						<view>失败原因</view>
						<view class='input'>
							{{invoice.refusalReason}}
						</view>
					</view>
          <view class='item acea-row row-between-wrapper acea-row-2'>
						<view>开票凭证</view>

            <view class="input acea-row row-center-wrapper">
              <view class='pictrue' v-for="(item,i) in invoice.invoiceProof" :key="i">
                <image :src='item' mode="aspectFill"></image>
                <view class="close acea-row row-center-wrapper" @tap='DelPic(item,i)'>
                  <view class="iconfont icon-guanbi1"></view>
                </view>
              </view>

              <template v-if="invoice.invoiceStatus == 0 || invoice.invoiceStatus == 1">
                <view class='upload-pic' v-if="invoice.invoiceProof || invoice.invoiceProof.length < 6" @click='uploadpic("Z")'>
                  <text class='iconfont icon-icon25201'></text>
                  <view>上传图片</view>
                </view>
              </template>
            </view>

					</view>
          <view class='item acea-row row-between-wrapper acea-row-2'>
						<view>结算凭证</view>
            <view class="input acea-row row-center-wrapper">
              <view class="picEwm" v-if="invoice.closingProof">
                <image v-for="item in invoice.closingProof" :src="item"></image>
              </view>
            </view>
					</view>
          
          <view class='item acea-row row-between-wrapper'>
						<view>备注</view>
						<view class='input'>
							<view>{{invoice.mark}}</view>
						</view>
					</view>

				</view>
				<button class='modifyBnt bg_color' @click='submitInvoicePics' v-if="invoice.invoiceStatus == 0 || invoice.invoiceStatus == 1">提交开票凭证</button>
			</view>
		<!-- </form> -->
	</view>
</template>

<script>
	import {
		closingInvoiceApi,
		userClosingInfoApi
	} from '@/api/user.js';
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		mapGetters
	} from "vuex";
	import { submitInvoicePics } from '@/api/invoicerecord';
	let app = getApp();
	const CACHE_ADDRESS = {};
	export default {
		data() {
			return {
				theme: app.globalData.theme,
				userInfo: null,
				invoice: {},
				id: '',
			};
		},
		computed: {
			...mapGetters(['isLogin']),
		},
		onLoad(option) {
			this.id = option.id
			if (!this.isLogin) {
				toLogin();
			} else {
				this.getUserInfo();
				this.getUserClosingInfo(this.id)
			}
		},
		methods: {
			getUserInfo(data) {
				this.$store.dispatch('USERINFO').then(res => {
					this.userInfo = res;
				});
			},
			/**
			 * 用户开票详情
			 */
			getUserClosingInfo(id) {
				let that = this;
				userClosingInfoApi({ id: id }).then(res => {
					uni.hideLoading();
          res.data.closingProof = res.data.closingProof ? JSON.parse(res.data.closingProof) : []
          res.data.invoiceProof = res.data.invoiceProof ? JSON.parse(res.data.invoiceProof) : []
					this.invoice = res.data;
				}).catch(msg => {
					uni.hideLoading();
					return that.$util.Tips({
						title: msg || '提交失败，请稍后在再试！'
					});
				});

			},

			/**上传文件*/
			uploadpic: function(type) {
				let that = this;
				that.$util.uploadImageOne({
					url: 'upload/image',
					name: 'multipart',
					model: "user",
					pid: 1
				}, function(res) {
          let pics = that.invoice.invoiceProof || []
					pics.push(res);
					that.$set(that.invoice, 'invoiceProof', pics);
				});
			},

      //删除图片
			DelPic(item, i) {
				let pic = [...this.invoice.invoiceProof];
				pic.splice(i, 1);
				this.$set(this.invoice, 'invoiceProof', pic);
			},

      submitInvoicePics() {
        if(!this.invoice.invoiceProof || !this.invoice.invoiceProof.length) {
          return this.$util.Tips({
            title: '请上传开票凭证'
          });
        }
        submitInvoicePics({
          id: this.id,
          invoiceProof: JSON.stringify(this.invoice.invoiceProof)
        }).then(res => {
          if(res.code == 200) {
            this.$util.Tips({
              title: '提交成功'
            });
            // this.getUserClosingInfo(this.id)
            setTimeout(()=>{
              uni.navigateBack()
            },1000)
          }
        })
      }
		}
	}
</script>

<style scoped lang="scss">
	.fontColor {
		color: #868686;
	}

	.personal-data .wrapper {
		margin: 10rpx 0;
		background-color: #fff;
		padding: 36rpx 30rpx 13rpx 30rpx;
	}

	.personal-data .wrapper .title {
		margin-bottom: 30rpx;
		font-size: 32rpx;
		color: #282828;
	}

	.personal-data .wrapper .wrapList .item {
		width: 690rpx;
		height: 160rpx;
		background-color: #f8f8f8;
		border-radius: 20rpx;
		margin-bottom: 22rpx;
		padding: 0 30rpx;
		position: relative;
		border: 2rpx solid #f8f8f8;
		box-sizing: border-box;
	}

	.personal-data .wrapper .wrapList .item.on {
		border-color: $theme-color;
		border-radius: 20rpx;
		background-image: url("");
		background-size: 100% 100%;
		background-color: #fff9f9;
		background-repeat: no-repeat;
	}

	.personal-data .wrapper .wrapList .item .picTxt {
		width: 445rpx;
	}

	.personal-data .wrapper .wrapList .item .picTxt .pictrue {
		width: 96rpx;
		height: 96rpx;
		position: relative;
	}

	.personal-data .wrapper .wrapList .item .picTxt .pictrue image,
	.pictrue button {
		width: 100%;
		height: 100%;
		border-radius: 50%;
	}

	.personal-data .wrapper .wrapList .item .picTxt .pictrue .alter {
		width: 30rpx;
		height: 30rpx;
		border-radius: 50%;
		position: absolute;
		bottom: 0;
		right: 0;
	}

	.personal-data .wrapper .wrapList .item .picTxt .text {
		width: 325rpx;
	}

	.personal-data .wrapper .wrapList .item .picTxt .text .name {
		width: 100%;
		font-size: 30rpx;
		color: #282828;
	}

	.personal-data .wrapper .wrapList .item .picTxt .text .phone {
		font-size: 24rpx;
		color: #999;
		margin-top: 10rpx;
	}

	.personal-data .wrapper .wrapList .item .bnt {
		font-size: 24rpx;
		background-color: #fff;
		border-radius: 27rpx;
		width: 140rpx;
		height: 54rpx;
		border: 2rpx solid $theme-color;
	}

	.personal-data .wrapper .wrapList .item .currentBnt {
		position: absolute;
		right: 0;
		top: 0;
		font-size: 26rpx;
		background-color: rgba(233, 51, 35, 0.1);
		width: 140rpx;
		height: 48rpx;
		border-radius: 0 20rpx 0 20rpx;
	}

	.personal-data .list {
		margin-top: 30rpx;
		background-color: #fff;
	}

	.personal-data .list .item {
		border-bottom: 1rpx solid #f2f2f2;
		padding: 24rpx;
		font-size: 32rpx;
		color: #333333;
	}

	.personal-data .list .item .phone {
		width: 160rpx;
		height: 56rpx;
		font-size: 24rpx;
		color: #fff;
		line-height: 56rpx;
		border-radius: 32rpx
	}

	.personal-data .list .item .pictrue {
		width: 80rpx;
		height: 80rpx;
		position: relative;
	}

	.personal-data .list .item .pictrue image {
		width: 100%;
		height: 100%;
		border-radius: 50%;
	}

	.personal-data .list .item .pictrue .alter {
		width: 30rpx;
		height: 30rpx;
		border-radius: 50%;
		position: absolute;
		bottom: 0;
		right: 0;
	}

	.personal-data .list .item .input {
		width: 415rpx;
		text-align: right;
		color: #666666;
	}

	.personal-data .list .item .input .id {
		width: 365rpx;
	}

	.personal-data .list .item .input .iconfont {
		font-size: 35rpx;
	}

	.personal-data .modifyBnt {
		font-size: 32rpx;
		color: #fff;
		width: 690rpx;
		height: 90rpx;
		border-radius: 50rpx;
		text-align: center;
		line-height: 90rpx;
		margin: 76rpx auto 0 auto;
	}

	.bg_color {
		@include main_bg_color(theme);
	}

	.personal-data .logOut {
		font-size: 32rpx;
		text-align: center;
		width: 690rpx;
		height: 90rpx;
		border-radius: 45rpx;
		margin: 30rpx auto 0 auto;
	}

  .acea-row-2{
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    image{
      width: 100%;
      // height: 100rpx;
    }
  }
  .row-center-wrapper{
    display: flex;
    justify-content: flex-end;
  }
  .picEwm{
    width: 100%;
  }
  .upload-pic{
    width: 126rpx;
    height: 126rpx;
    border-radius: 4rpx;
    position: relative;
    border: 1px solid rgba(221, 221, 221, 1);
    font-size: 22rpx;
    color: #DDDDDD;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    text{
      font-size: 42rpx !important;
      color: #DDDDDD;
      margin-bottom: 10rpx;
    }
  }
  .pictrue{
    width: 126rpx !important;
		height: 126rpx !important;
		position: relative;
    margin-right: 10rpx;
    image{
      width: 100%;
      height: 100%;
    }
    .close{
      position: absolute;
      bottom: 0;
      right: 0;
    }
  }
</style>